home *** CD-ROM | disk | FTP | other *** search
- Path: mxsld2.pd.infn.it!LORETI
- From: loreti@mxsld2.pd.infn.it (Maurizio Loreti)
- Newsgroups: comp.lang.c
- Subject: Re: printf problems..
- Date: Wed, 17 Apr 1996 12:57:07 GMT
- Organization: I.N.F.N. Padova - CDF/CMS VAXcluster
- Message-ID: <4l2m9j$1e3s@serra.unipi.it>
- References: <4l1ubi$c3p@news.ysu.edu>
- Reply-To: loreti@mxsld2.pd.infn.it
- NNTP-Posting-Host: mxsld2.pd.infn.it
-
- In article <4l1ubi$c3p@news.ysu.edu>, bi287@yfn.ysu.edu (Brian T. Richardson) writes:
- >
- > I feel really stupid, but I cannot make printf add zeros
- > before a floating point number..
- >
- > I want it to output '02.11' not '2.11'
- >
- > I tried something like printf(temp, "%O2.2f", myvar)
- > and other varations and nothing has worked for
- > me, I know I'm missing something really obvious..
-
- Well, O2.2 is an error; you need a zero, not a letter O, and the width
- should be greater than the precision.
-
- cmssun1-22> cat foo.c
- #include <stdio.h>
-
- int main(){
- double x = 2.11;
-
- printf("%010.2f\n", x);
- return 0;
- }
- cmssun1-23> gcc -ansi -pedantic -Wall foo.c
- cmssun1-24> ./a.out
- 0000002.11
-
- --
- Maurizio Loreti http://mvxpd5.pd.infn.it/wwwcdf/mlo.html
- Un. of Padova, Dept. of Physics - Padova, Italy loreti@padova.infn.it
-